def factorial(n):
    s = 1
    for i in range(2, n+1):
        s *= i
    return s


def judge(n):
  # 拆数 累加每一位的阶乘和
  # 判断是否等于n
    s = 0
    m = n
    while n > 0:
        d = n % 10
        s += factorial(d)
        n //= 10

    if s == m:
        return True
    else:
        return False


def main():
    ans = []
    for i in range(1, 40586):
        if judge(i):
            ans.append(str(i))

    for i in sorted(ans):
        print(i, end=" ")


if __name__ == "__main__":
    main()
